import { baseUrl } from '@/utils/baseUrl.js'
import { getInfo } from '@/static/js/consult.js'
var setTime = null
export default {
	data() {
		return {
			baseUrl,
			dataList: [], // 详情页数据
			fontSize: '28rpx',
			showParse: true, // 富文本显示状态
			id: '',
			is_collect: 0,
			tagStyle: {
				table: 'box-sizing: border-box; border-top: 1px solid #dfe2e5; border-left: 1px solid #dfe2e5;',
				th: 'border-right: 1px solid #dfe2e5; border-bottom: 1px solid #dfe2e5;',
				td: 'border-right: 1px solid #dfe2e5; border-bottom: 1px solid #dfe2e5;',
				li: 'margin: 5px 0;'
			},
			scrollTop: 0, // 滚动距离顶部的距离
			nScrollTop: 0, // 滚动的新top
			nScrollTop2: null,
			scrollIndex: 1,
		};
	},
	onLoad(e) {
		var that = this
		this.id = e.id
	},
	onShow() {
		this.getInfo()
	},
	onReady() {

	},
	onUnload() {
		clearInterval(setTime)
	},
	computed: {},
	methods: {
		//详情
		getInfo() {
			getInfo({ id: this.id }).then(res => {
				if (res.code == 1) {
					this.dataList = res.data
					this.is_collect = res.data.is_collect
				}
			})

		},

		setScrollTop() {
			if (this.scrollIndex % 2 == 0) {
				this.nScrollTop2 = null
				this.scrollTop = this.nScrollTop
			} else {
				this.scrollTop = this.pScrollTop
				this.nScrollTop2 = this.nScrollTop
			}
			this.scrollIndex++
		},

		getScrollTop(e) {
			if (this.nScrollTop2 == null)
				this.nScrollTop = e.detail.scrollTop
		},

		navigate(e) {
			this.download(e.href)
		},

		//签订合同下载
		download(e) {
			uni.downloadFile({
				url: e, //下载地址接口返回
				success: (data) => {
					if (data.statusCode === 200) {
						//文件保存到本地
						uni.saveFile({
							tempFilePath: data.tempFilePath, //临时路径
							success: function (res) {
								uni.showToast({
									icon: 'none',
									mask: true,
									title: '文件下载成功，2秒后将自动打开', //保存路径  res.savedFilePath
									duration: 3000,
								});
								setTimeout(() => {
									//打开文档查看
									uni.openDocument({
										filePath: res.savedFilePath,
										success: function (res) {
											// console.log('打开文档成功');
										}
									});
								}, 2000)
							}
						});
					}
				},
				fail: (err) => {
					console.log(err);
					uni.showToast({
						icon: 'none',
						mask: true,
						title: '失败，请重新下载',
					});
				},
			});
		},

		//获取富文本内容
		getHtmlText(str) {
			return str = this.dataList.content.replace(/<[^<>]+>/g, "").replace(/&nbsp;/gi, "");
		}
	},
}